﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace AIC_PN
{
    public partial class BaoCaoMau8_2014 : MyFromBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPermission();
            if (!IsPostBack)
            {
                BindDataToControls();
                if (Request.QueryString["KyBaoCao"] != null)
                {
                    cboKyBaoCao.SelectedValue = Request.QueryString["KyBaoCao"];
                    cboKyBaoCao_SelectedIndexChanged(sender, e);
                }
            }
        }

        private void CheckPermission()
        {
            Dictionary<string, int> Role = MyCommon.CheckPermission("BaoCaoMau1");
            if (Role == null || Role["Xem"] == 0 || ((Role["Xem"] == 1 && Role["Sua"] == 0)))
            {
                Response.Redirect("Index.aspx?p=0");
            }
        }

        private void BindDataToControls()
        {
            if (Session["userid"] != null)
            {
                string sql = "Select DV.* " +
                             "From tblDonVi DV " +
                             "Inner Join tblUser U On U.DonViID=DV.ID " +
                             "Where U.ID=" + Session["userid"];
                DataTable dtDV = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
                tdTenDonVi.InnerHtml = "<b><i>Đơn vị báo cáo : " + dtDV.Rows[0]["TenDV"] + "</i></b>";
                sql = "Select ID,TenDM From tblDanhMuc Where MaDM='" + MyConst.DanhMuc.KyBaoCao.Ma + "' ";
                SqlDataReader reKyBaoCao = SqlHelper.ExecuteReader(CommandType.Text, sql);
                clsDataBind.CreateCombo("Tất cả", reKyBaoCao, cboKyBaoCao, 1, 0);
            }
        }

        protected void BindDataToTextField()
        {
            string sql = "SELECT CM_TenBaoCao,CM_ThoiGianBaoCao FROM dbo.tblBaoCaoMau8 WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND IsCommon = 1";
            List<SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
            lstParameters.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, MyCommon.GetDonViID(Session["userid"].ToString())));
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParameters);
            if (dt.Rows.Count != 0)
            {
                txtTenBaoCao.Text = dt.Rows[0]["CM_TenBaoCao"].ToString();
                txtNgayBaoCao.Text = dt.Rows[0]["CM_ThoiGianBaoCao"].ToString();
            }
        }

        private void BindDataToGrid()
        {
            List<SqlParameter> lstParams = new List<SqlParameter>();
            lstParams.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
            lstParams.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, Session["userdonvi"]));
            lstParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));

            string sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen = 1";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData.DataSource = dt;
            grvData.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =2";
            DataTable dt2 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData2.DataSource = dt2;
            grvData2.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =3";
            DataTable dt3 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData3.DataSource = dt3;
            grvData3.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =4";
            DataTable dt4 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData4.DataSource = dt4;
            grvData4.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =5";
            DataTable dt5 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData5.DataSource = dt5;
            grvData5.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =6";
            DataTable dt6 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData6.DataSource = dt6;
            grvData6.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =7";
            DataTable dt7 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData7.DataSource = dt7;
            grvData7.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =8";
            DataTable dt8 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData8.DataSource = dt8;
            grvData8.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =9";
            DataTable dt9 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData9.DataSource = dt9;
            grvData9.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =10";
            DataTable dt10 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData10.DataSource = dt10;
            grvData10.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =11";
            DataTable dt11 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData11.DataSource = dt11;
            grvData11.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =12";
            DataTable dt12 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData12.DataSource = dt12;
            grvData12.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =13";
            DataTable dt13 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData13.DataSource = dt13;
            grvData13.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
                        "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
                        "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
                        "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =14";
            DataTable dt14 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData14.DataSource = dt14;
            grvData14.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
                        "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
                        "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
                        "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =15";
            DataTable dt15 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData15.DataSource = dt8;
            grvData15.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
                        "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
                        "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
                        "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =16";
            DataTable dt16 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData16.DataSource = dt16;
            grvData16.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
                        "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
                        "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
                        "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =17";
            DataTable dt17 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData17.DataSource = dt17;
            grvData17.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
                        "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
                        "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
                        "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =18";
            DataTable dt18 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData18.DataSource = dt18;
            grvData18.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
                        "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
                        "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
                        "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =19";
            DataTable dt19 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData19.DataSource = dt19;
            grvData19.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
                        "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
                        "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
                        "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =20";
            DataTable dt20 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData20.DataSource = dt20;
            grvData20.DataBind();

            btnLuu.Visible = true;
            grvData.Visible = true;
            grvData2.Visible = true;
            grvData3.Visible = true;
            grvData4.Visible = true;
            grvData5.Visible = true;
            grvData6.Visible = true;
            grvData7.Visible = true;
            grvData8.Visible = true;
            grvData9.Visible = true;
            grvData10.Visible = true;
            grvData11.Visible = true;
            grvData12.Visible = true;
            grvData13.Visible = true;
            grvData14.Visible = true;
            grvData15.Visible = true;
            grvData16.Visible = true;
            grvData17.Visible = true;
            grvData18.Visible = true;
            grvData19.Visible = true;
            grvData20.Visible = true;
        }

        public void MergeRows(GridView gridView)
        {
            //for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
            //{
            //    GridViewRow row = gridView.Rows[rowIndex];
            //    GridViewRow previousRow = gridView.Rows[rowIndex + 1];

            //    if (row.Cells[13].Text == previousRow.Cells[13].Text)
            //    {
            //        row.Cells[13].RowSpan = previousRow.Cells[13].RowSpan < 2 ? 2 : previousRow.Cells[13].RowSpan + 1;
            //        previousRow.Cells[13].Visible = false;
            //    }
            //    if (row.Cells[13].Text.Trim() == previousRow.Cells[13].Text.Trim() && row.Cells[13].Text.Trim() == row.Cells[14].Text.Trim())
            //    {
            //        row.Visible = false;
            //    }
            //}
        }

        public void MergeRowsUse(GridView gridView)
        {
            for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
            {
                GridViewRow row = gridView.Rows[rowIndex];
                GridViewRow previousRow = gridView.Rows[rowIndex + 1];

                if (row.Cells[0].Text == previousRow.Cells[0].Text)
                {
                    row.Cells[0].RowSpan = previousRow.Cells[0].RowSpan < 2 ? 2 : previousRow.Cells[0].RowSpan + 1;
                    previousRow.Cells[0].Visible = false;
                }
                if (row.Cells[0].Text.Trim() == previousRow.Cells[0].Text.Trim() && row.Cells[0].Text.Trim() == row.Cells[1].Text.Trim())
                {
                    row.Visible = false;
                }
            }
        }

        #region Events

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("Index.aspx");
        }

        protected void cboKyBaoCao_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboKyBaoCao.SelectedIndex > 0)
            {
                btnLuu.Visible = false;
                grvData.Visible = false;
                grvData.EditIndex = -1;
                BindDataToGrid();
                if (((DataTable)grvData.DataSource).Rows.Count == 0)
                {
                    SqlTransaction MyTran = SqlHelper.BeginTransaction();
                    try
                    {
                        List<SqlParameter> lstParams = new List<SqlParameter>();
                        lstParams.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
                        lstParams.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, Session["userdonvi"]));
                        lstParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                        string sql = "INSERT INTO dbo.tblBaoCaoMau8( KyBaoCaoID_DM ,DonViID ,TenBaoCaoID_DM ,F1,IsCommon,UserID)   " +
                                 "SELECT @KyBaoCaoID_DM ,@DonViID ,B.ID,0,0,@UserID FROM dbo.tblDanhMucBaoCao A " +
                                 "INNER JOIN dbo.tblDanhMucBaoCao B ON A.ID = B.FatherID WHERE B.MaDM = 103";
                        SqlHelper.ExecuteNonQuery(System.Data.CommandType.Text, sql, lstParams);
                        sql = "INSERT INTO dbo.tblBaoCaoMau8(KyBaoCaoID_DM,DonViID,IsCommon ,UserID) " +
                              "VALUES( @KyBaoCaoID_DM,@DonViID,1,@UserID)";
                        SqlHelper.ExecuteNonQuery(System.Data.CommandType.Text, sql, lstParams);
                        MyTran.Commit();
                    }
                    catch
                    {
                        MyTran.Rollback();
                    }
                    grvData.EditIndex = -1;
                    BindDataToGrid();
                }
                else
                {
                    BindDataToTextField();
                    grvData.Visible = true;
                }
                pnl.Visible = true;
            }
            else
            {
                btnLuu.Visible = false;
                grvData.Visible = false;
                pnl.Visible = false;
            }
        }

        protected void btnLuu_Click(object sender, EventArgs e)
        {

            string sSQL = "Update tblBaoCaoMau8 Set CM_TenBaoCao=@CM_TenBaoCao,CM_ThoiGianBaoCao=@CM_ThoiGianBaoCao" +
                            " Where IsCommon=1 And DonViID=" + MyCommon.GetDonViID(Session["userid"].ToString()) + " And KyBaoCaoID_DM=" + cboKyBaoCao.SelectedValue;

            List<SqlParameter> lstParameter = new List<SqlParameter>();
            lstParameter.Add(SqlHelper.CreateParameterObject("@CM_TenBaoCao", SqlDbType.NVarChar, ParameterDirection.Input, txtTenBaoCao.Text.Trim()));
            lstParameter.Add(SqlHelper.CreateParameterObject("@CM_ThoiGianBaoCao", SqlDbType.NVarChar, ParameterDirection.Input, txtNgayBaoCao.Text.Trim()));


            SqlHelper.ExecuteNonQuery(CommandType.Text, sSQL, lstParameter);

            MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);

        }

        private static void AddMergedCells(GridViewRow objgridviewrow, TableCell objtablecell, int colspan, int rowspan, string celltext)
        {
            objtablecell = new TableCell();
            objtablecell.Text = celltext;
            objtablecell.ColumnSpan = colspan;
            objtablecell.RowSpan = rowspan;
            objtablecell.HorizontalAlign = HorizontalAlign.Center;
            objgridviewrow.Cells.Add(objtablecell);
        }
        #endregion Events

        #region GridCommand 1
        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData.Rows[grvData.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData.Rows[grvData.EditIndex].Cells[2].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData);
        }
        #endregion GridCommand 1

        #region GridCommand 2
        protected void grvData2_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData2_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData2.Rows[grvData2.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData2_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData2.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData2.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData2_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData2);
        }
        #endregion GridCommand 1

        #region GridCommand 3
        protected void grvData3_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData3_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData3.Rows[grvData3.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData3.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData3_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData3.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData3_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData3.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData3_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData3.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData3_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData3);
        }
        #endregion GridCommand 1

        #region GridCommand 4
        protected void grvData4_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData4_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData4.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData4_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData4_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData4.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData4_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData4.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData4_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData4);
        }
        #endregion GridCommand 1

        #region GridCommand 5
        protected void grvData5_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData5_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData5.Rows[grvData5.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData5.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData5_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData5.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData5_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData5.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData5_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData5.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData5_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData5);
        }
        #endregion GridCommand 1

        #region GridCommand 6
        protected void grvData6_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData6_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData6.Rows[grvData6.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData6.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData6_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData6.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData6_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData6.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData6_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData6.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData6_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData6);
        }
        #endregion GridCommand 1

        #region GridCommand 7
        protected void grvData7_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData7_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData7.Rows[grvData7.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData7.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData7_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData7.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData7_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData7.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData7_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData7.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData7_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData7);
        }
        #endregion

        #region GridCommand 8
        protected void grvData8_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData8_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData8.Rows[grvData8.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData8.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData8_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData8.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData8_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData8.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData8_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData8.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData8_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData8);
        }
        #endregion

        #region GridCommand 9
        protected void grvData9_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData9_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData9.Rows[grvData9.EditIndex].Cells[2].Controls[0];
                TextBox txtF2 = (TextBox)grvData9.Rows[grvData9.EditIndex].Cells[3].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData9.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData9_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData9.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData9_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData9.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData9_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData9.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData9_PreRender(object sender, EventArgs e)
        {
            //MergeRowsUse(grvData9);
        }

        protected void grvData9_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Cán bộ Hội");
                AddMergedCells(objgridviewrow, objtablecell, 1, 1, "Cấp ĐM");
                AddMergedCells(objgridviewrow, objtablecell, 1, 1, "Cấp CS");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);
            }
        }
        #endregion

        #region GridCommand 10
        protected void grvData10_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData10_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData10.Rows[grvData10.EditIndex].Cells[2].Controls[0];
                TextBox txtF2 = (TextBox)grvData10.Rows[grvData10.EditIndex].Cells[3].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData10.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData10_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData10.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData10_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData10.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData10_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData10.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData10_PreRender(object sender, EventArgs e)
        {
            //MergeRowsUse(grvData10);
        }

        protected void grvData10_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "CB Hội DTTS	");
                AddMergedCells(objgridviewrow, objtablecell, 1, 1, "Cấp ĐM");
                AddMergedCells(objgridviewrow, objtablecell, 1, 1, "Cấp CS");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);
            }
        }
        #endregion

        #region GridCommand 11
        protected void grvData11_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData11_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData11.Rows[grvData11.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData11.Rows[grvData11.EditIndex].Cells[2].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF2.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData11.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData11_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData11.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData11_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData11.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData11_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData11.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData11_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData11);
        }
        #endregion

        #region GridCommand 12
        protected void grvData12_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData12_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData12.Rows[grvData12.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData12.Rows[grvData12.EditIndex].Cells[2].Controls[0];
                TextBox txtF3 = (TextBox)grvData12.Rows[grvData12.EditIndex].Cells[3].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData12.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData12_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData12.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData12_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData12.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData12_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData12.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData12_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData12);
        }

        protected void grvData12_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Danh mục");
                AddMergedCells(objgridviewrow, objtablecell, 3, 1, "Lĩnh vực");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Đảng");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Chính quyền");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Các đoàn thể khác");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);
            }
        }
        #endregion

        #region GridCommand 13
        protected void grvData13_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData13_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData13.Rows[grvData13.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData13.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData13_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData13.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData13_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData13.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData13_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData13.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData13_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData13);
        }
        #endregion

        #region GridCommand 14
        protected void grvData14_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData14_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData14.Rows[grvData14.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData14.Rows[grvData14.EditIndex].Cells[2].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData14.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData14_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData14.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData14_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData14.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData14_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData14.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData14_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData14);
        }
        #endregion

        #region GridCommand 15
        protected void grvData15_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData15_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData15.Rows[grvData15.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData15.Rows[grvData15.EditIndex].Cells[2].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData15.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData15_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData15.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData15_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData15.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData15_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData15.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData15_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData15);
        }
        #endregion

        #region GridCommand 16
        protected void grvData16_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData16_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData16.Rows[grvData16.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData16.Rows[grvData16.EditIndex].Cells[2].Controls[0];
                TextBox txtF3 = (TextBox)grvData16.Rows[grvData16.EditIndex].Cells[3].Controls[0];
                TextBox txtF4 = (TextBox)grvData16.Rows[grvData16.EditIndex].Cells[4].Controls[0];
                TextBox txtF5 = (TextBox)grvData16.Rows[grvData16.EditIndex].Cells[5].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData16.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData16_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData16.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData16_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData16.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData16_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData16.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData16_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData16);
        }
        protected void grvData16_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Nội dung");
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Cấp đầu mối");
                AddMergedCells(objgridviewrow, objtablecell, 3, 1, "Cấp cơ sở");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Tổ chức Hội");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Cán bộ Hội");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Tổ chức Hội");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Cán bộ Hội");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Hội viên");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);
            }
        }
        #endregion

        #region GridCommand 17
        protected void grvData17_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData17_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData17.Rows[grvData17.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData17.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData17_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData17.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData17_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData17.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData17_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData17.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData17_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData17);
        }
        #endregion

        #region GridCommand 18
        protected void grvData18_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData18_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData18.Rows[grvData18.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData18.Rows[grvData18.EditIndex].Cells[2].Controls[0];
                TextBox txtF3 = (TextBox)grvData18.Rows[grvData18.EditIndex].Cells[3].Controls[0];
                TextBox txtF4 = (TextBox)grvData18.Rows[grvData18.EditIndex].Cells[4].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData18.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData18_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData18.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData18_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData18.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData18_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData18.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData18_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData18);
        }

        protected void grvData18_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Thành tích khen thưởng");
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Cấp  Đầu mối TT Bộ");
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Cấp cơ sở");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Tập thể");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Cá nhân");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Tập thể");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Cá nhân");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);
            }
        }
        #endregion

        #region GridCommand 19
        protected void grvData19_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData19_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData19.Rows[grvData19.EditIndex].Cells[2].Controls[0];
                TextBox txtF2 = (TextBox)grvData19.Rows[grvData19.EditIndex].Cells[3].Controls[0];
                TextBox txtF3 = (TextBox)grvData19.Rows[grvData19.EditIndex].Cells[4].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData19.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData19_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData19.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData19_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData19.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData19_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData19.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData19_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData19);
        }

        protected void grvData19_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "STT");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Tên mô hình");
                AddMergedCells(objgridviewrow, objtablecell, 1, 1, "Cấp thực hiện");
                AddMergedCells(objgridviewrow, objtablecell, 1, 1, "Số lượng");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Phạm vi triển khai mô hình (tổng số cơ sở Hội có mô hình)");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "(ĐM/cơ sở)");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "(CLB, tổ…)/tổng số thành viên");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);
            }
        }
        #endregion

        #region GridCommand 20
        protected void grvData20_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData20_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData20.Rows[grvData20.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData20.Rows[grvData20.EditIndex].Cells[2].Controls[0];
                TextBox txtF3 = (TextBox)grvData20.Rows[grvData20.EditIndex].Cells[3].Controls[0];
                TextBox txtF4 = (TextBox)grvData20.Rows[grvData20.EditIndex].Cells[4].Controls[0];
                TextBox txtF5 = (TextBox)grvData20.Rows[grvData20.EditIndex].Cells[5].Controls[0];
                TextBox txtF6 = (TextBox)grvData20.Rows[grvData20.EditIndex].Cells[6].Controls[0];
                TextBox txtF7 = (TextBox)grvData20.Rows[grvData20.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F6", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF6.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F7", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF7.Text.Equals("") ? "0" : txtF4.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[F6]=@F6,[F7]=@F7,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData20.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData20_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData20.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData20_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData20.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData20_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData20.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData20_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData20);
        }

        protected void grvData20_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Cấp");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Tổng số");
                AddMergedCells(objgridviewrow, objtablecell, 6, 1, "Tên mô hình mới tập hợp thu hút hội viên");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Nữ thanh niên");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Dân tộc");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Tôn giáo");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Nữ trí thức");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "LĐ nữ khu CN, CX");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Mô hình ");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);
            }
        }
        #endregion
    }
}
